package edu.fmi.st.epf.types.team.common.util;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.epf.library.edit.util.ModelStructure;
import org.eclipse.epf.uma.ContentPackage;
import org.eclipse.epf.uma.CustomCategory;

import edu.fmi.st.epf.types.team.common.handler.TeamCustomTypeHandler;
import eu.tanov.epf.pv.service.types.util.CustomTypeHelper;

public class TeamHelper {
	public static final String CATEGORY_NAME = "Teams"; //$NON-NLS-1$

	public static final String[] TEAMS_PATH;
	static {
		TEAMS_PATH = new String[ModelStructure.DEFAULT_DOMAIN_PATH.length];
		// -1, because last is used for Project category
		System.arraycopy(ModelStructure.DEFAULT_DOMAIN_PATH, 0, TEAMS_PATH, 0,
				TEAMS_PATH.length - 1);
		TEAMS_PATH[TEAMS_PATH.length - 1] = TeamHelper.CATEGORY_NAME;
	}

	private TeamHelper() {

	}

	public static boolean isTeam(Object o) {
		if (!(o instanceof CustomCategory)) {
			return false;
		}
		final CustomCategory customCategory = (CustomCategory) o;

		if (!(customCategory.eContainer() instanceof ContentPackage)) {
			return false;
		}
		final ContentPackage contentPackage = (ContentPackage) customCategory
				.eContainer();

		return CATEGORY_NAME.equals(contentPackage.getName());
	}

	public static EClass getCustomType() {
		return CustomTypeHelper.getCustomType(TeamCustomTypeHandler.TYPE_NAME);
	}

	public static boolean isRegistered() {
		return CustomTypeHelper.isRegistered(TeamCustomTypeHandler.TYPE_NAME);
	}
}
